package com.imooc.demo.controller;

import com.imooc.demo.config.Application;
import com.imooc.demo.dto.UsDto;
import com.imooc.demo.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author cwx897169 on 2020/3/8 9:21
 * @param:
 * @return:
 * @Description: 请求入口
 */
@RestController
@RequestMapping("/user")
public class UserController {


    private static final Logger LOG = LoggerFactory.getLogger(Application.class);

    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public String login( UsDto usDto ) {
        LOG.info("登录开始, {}", usDto.toString());

        Map<String, String> map = new HashMap<>();
        map.put("key", "value");
        map.put("key", "value");
        map.put("key", "value");
        map.put("key", "value");
        printLog();


        // todo 调用service方法
        UsDto usDto1 = userService.doLogin(usDto);

        if (usDto == null) {
            LOG.warn("用户或密码错");
            return "用户或密码错";
        } else {
            LOG.info("登录成功");
            return "登录成功";
        }
    }

    private void printLog() {
        System.out.println("打印一");
        System.out.println("打印二");
        System.out.println("打印三");
    }

    @RequestMapping("/list")
    public String list() {
        LOG.info("查询开始");
        userService.list();
        return "success";
    }

}